package red.sms.business;

import red.sms.db.dao.SmsMoDAO;
import red.sms.db.entity.SmsMO;
import red.sms.domain.GetSmsResult;

public class MainProcess {

	/**
	 * TODO: checkSMS in database
	 */
	public static GetSmsResult getSMS(){
		SmsMoDAO moDAO = new SmsMoDAO();
		GetSmsResult getSmsResult = new GetSmsResult();
		SmsMO smsMo = moDAO.dequeue();
		// Step 1: Check a record in MO
		if ((smsMo.getRequestId() == null)){
			getSmsResult.setErrorCode(11);
			getSmsResult.setErrorMessage("no record");
		}
		//Step 2: get the first record in MO
		else{
			getSmsResult.setErrorCode(0);
			getSmsResult.setErrorMessage("get SMS message success");
			getSmsResult.setContent(smsMo.getRequestId() + "-" + smsMo.getPhoneNumber() + "-" + smsMo.getInfo());
		}
		//Step 3: return result
		return getSmsResult;
	}
	
	public static void main(String args[]){
		GetSmsResult getSmsResult = MainProcess.getSMS();
		System.out.println(getSmsResult.getErrorMessage());
		System.out.println(getSmsResult.getContent());
	}
	
}
